From 3bd2705b7acad4a5fefc19a34a087b6335b1ec92 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 25 Jun 2014 23:43:35 -0400 Subject: [PATCH] GtkScrolledWindow: Use style classes for shadow Translate shadow != None into the FRAME style class. This doesn't change the style classes used for drawing, it only sets the style class permanently instead of saving and restoring in draw(). https://bugzilla.gnome.org/show_bug.cgi?id=732256 --- gtk/gtkscrolledwindow.c | 74 +++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 87d3008807..f9d9e29b6a 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -1226,6 +1226,7 @@ gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window, GtkShadowType type) { GtkScrolledWindowPrivate *priv; + GtkStyleContext *context; g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window)); g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT); @@ -1236,6 +1237,12 @@ gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window, { priv->shadow_type = type; + context = gtk_widget_get_style_context (GTK_WIDGET (scrolled_window)); + if (type != GTK_SHADOW_NONE) + gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME); + else + gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME); + if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window))) gtk_widget_queue_draw (GTK_WIDGET (scrolled_window)); @@ -1544,11 +1551,8 @@ gtk_scrolled_window_draw_scrollbars_junction (GtkScrolledWindow *scrolled_window state = gtk_widget_get_state_flags (widget); - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_get_border (context, state, &border); - gtk_style_context_restore (context); junction_rect.x = padding.left + border.left; junction_rect.y = padding.top + border.top; @@ -1595,58 +1599,50 @@ gtk_scrolled_window_draw (GtkWidget *widget, GtkScrolledWindowPrivate *priv = scrolled_window->priv; GtkAllocation relative_allocation; GtkStyleContext *context; + gboolean scrollbars_within_bevel; context = gtk_widget_get_style_context (widget); gtk_scrolled_window_relative_allocation (widget, &relative_allocation); gtk_render_background (context, cr, 0, 0, - gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget)); + gtk_widget_get_allocated_width (widget), + gtk_widget_get_allocated_height (widget)); if (priv->hscrollbar_visible && priv->vscrollbar_visible) gtk_scrolled_window_draw_scrollbars_junction (scrolled_window, cr); - if (priv->shadow_type != GTK_SHADOW_NONE) - { - gboolean scrollbars_within_bevel; - - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME); - - gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL); - - if (!scrollbars_within_bevel) - { - GtkStateFlags state; - GtkBorder padding, border; - - state = gtk_widget_get_state_flags (widget); - gtk_style_context_get_padding (context, state, &padding); - gtk_style_context_get_border (context, state, &border); + gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL); - relative_allocation.x -= padding.left + border.left; - relative_allocation.y -= padding.top + border.top; - relative_allocation.width += padding.left + padding.right + border.left + border.right; - relative_allocation.height += padding.top + padding.bottom + border.top + border.bottom; - } - else - { - relative_allocation.x = 0; - relative_allocation.y = 0; - relative_allocation.width = gtk_widget_get_allocated_width (widget); - relative_allocation.height = gtk_widget_get_allocated_height (widget); - } + if (!scrollbars_within_bevel) + { + GtkStateFlags state; + GtkBorder padding, border; - gtk_render_frame (context, cr, - relative_allocation.x, - relative_allocation.y, - relative_allocation.width, - relative_allocation.height); + state = gtk_widget_get_state_flags (widget); + gtk_style_context_get_padding (context, state, &padding); + gtk_style_context_get_border (context, state, &border); - gtk_style_context_restore (context); + relative_allocation.x -= padding.left + border.left; + relative_allocation.y -= padding.top + border.top; + relative_allocation.width += padding.left + padding.right + border.left + border.right; + relative_allocation.height += padding.top + padding.bottom + border.top + border.bottom; + } + else + { + relative_allocation.x = 0; + relative_allocation.y = 0; + relative_allocation.width = gtk_widget_get_allocated_width (widget); + relative_allocation.height = gtk_widget_get_allocated_height (widget); } + gtk_render_frame (context, cr, + relative_allocation.x, + relative_allocation.y, + relative_allocation.width, + relative_allocation.height); + GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr); return FALSE; -- 2.30.2